using System;
using System.Collections.Generic;
using System.Text;

using libsecondlife;
using libsecondlife.InventorySystem;

using Feathertail;

namespace NestBox.Inventory
{
    class outfit : Feathertail.Command
    {
        private FeathertailClient _Client;

        #region Command Members

        public void Setup(FeathertailClient Client)
        {
            _Client = Client;

            if (!_Client.FeathertailState.ContainsKey(Helpers.CurrentDirectoryKey))
            {
                _Client.FeathertailState[Helpers.CurrentDirectoryKey] = "/";
            }
        }

        public string HandleInput(string[] CmdLine)
        {
            if (CmdLine.Length < 2)
            {
                return GetHelpText();
            }

            StringBuilder sb = new StringBuilder();

            string curDirectory = (string)_Client.FeathertailState[Helpers.CurrentDirectoryKey];
            string targetDir = "";

            if (CmdLine[1].Equals(".."))
            {
                targetDir = curDirectory.Substring(0, curDirectory.LastIndexOf("/"));
            }
            else if (CmdLine[1].StartsWith("/"))
            {
                targetDir += NestBox.Inventory.Helpers.combineCmdArg(CmdLine);
            }
            else
            {
                if (!curDirectory.Equals("/"))
                {
                    targetDir = curDirectory + "/";

                }

                targetDir += NestBox.Inventory.Helpers.combineCmdArg(CmdLine);
            }

            InventoryFolder iFolder = _Client.Inventory.getFolder(targetDir);

            if (iFolder == null)
            {
                return "Could not find directory: " + targetDir;
            }

            _Client.Appearance.WearOutfit(iFolder);
            return sb.ToString();
        }

        public string[] GetCommandStrings()
        {
            return new string[] { "outfit" };
        }

        public string GetSummaryText()
        {
            return "Put on an outfit from a folder";
        }

        public string GetHelpText()
        {
            return "Usage: outfit [directory]" + Environment.NewLine + "Example: outfit \"Agent Smith\"";
        }

        #endregion
    }
}
